using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Net;
using System.Web;
using System.Web.Profile;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Dzzzr;

namespace NWS
{
	/// <summary>
	/// Page with google maps control
	/// </summary>
	public partial class Google : System.Web.UI.Page
	{
		/// <summary>
		/// Set up page for AJAX using 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				ddlDelay.SelectedValue = "10000";
				RefreshGameList();
				if (!String.IsNullOrEmpty(ddlGames.SelectedValue))
					RefreshMarkerList(Convert.ToInt32(ddlGames.SelectedValue));

			}
			lbMarkers.Attributes.Add("ondblclick", "MoveToSelectedMarker();");
		}

		private void RefreshGameList()
		{
			//MonitoringClient monitoringClient = new MonitoringClient();
			//Game[] games = monitoringClient.GetGameList(Helper.UserName, Helper.Password);
			List<Game> games = Game.GetGameList(Helper.TeamID);
			ddlGames.DataSource = games;
			//ddlGames.DataMember = "ID";
			ddlGames.DataValueField = "ID";
			ddlGames.DataTextField = "Name";
			ddlGames.DataBind();
			if (games.Count > 0)
				Helper.UpdateGame(games[0].ID);
		}

		private void RefreshMarkerList(int gameID)
		{
			//AJAXService service = new AJAXService();
			List<Entity> entities = Entity.GetGameEntityList(gameID);
			lbMarkers.DataSource = entities;
			lbMarkers.DataValueField = "ID";
			lbMarkers.DataTextField = "Name";
			lbMarkers.DataBind();
		}

		protected void ddlGames_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (!String.IsNullOrEmpty(ddlGames.SelectedValue))
			{
			    int gameID = Convert.ToInt32(ddlGames.SelectedValue);
			    RefreshMarkerList(gameID);
			    Helper.UpdateGame(gameID);
			}
		}
	}
}
